package com.ymk.cmd;


import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.work.WorkBO;
import com.ymk.bo.work.WorkImgBO;

import com.ymk.core.code.cmd.WorkCmdCode;

import com.ymk.service.IWorkImgService;
import com.ymk.service.IWorkService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class WorkGetCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkBO reqData = super.getData(sign, WorkBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("id", reqData.getId())
                .addParam("loadWorkType",true)
                .addParam("loadWorkContent",true)
                .setReturnStruct(sign.getReturnStruct());
        WorkBO respData = this.workService.get(paramsBuilder.build());

        paramsBuilder.clearParam().addParam("workId",reqData.getId());
        //查询图片信息
        List<WorkImgBO> imgBOListlist = workImgService.list(paramsBuilder.build());
        respData.setWorkImgList(imgBOListlist);

        respSign.setSource(super.getSource(respData));

        return respSign;
    }


    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkBO reqData = super.getData(sign, WorkBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("id", reqData.getId())
                .addParam("loadWorkType",true)
                .addParam("loadWorkContent",true)
                .setReturnStruct(sign.getReturnStruct());
        WorkBO respData = this.workService.get(paramsBuilder.build());

        paramsBuilder.clearParam().addParam("workId",reqData.getId());
        //查询图片信息
        List<WorkImgBO> imgBOListlist = workImgService.list(paramsBuilder.build());
        respData.setWorkImgList(imgBOListlist);

        respSign.setSource(super.getSource(respData));

        return respSign;
    }


    @Override
    public String getCmdCode() {
        return WorkCmdCode.WORK_GET;
    }

    @Override
    public boolean anon(CmdSign sign) {
        return true;
    }


    @Autowired
    private IWorkImgService workImgService;
    @Autowired
    private IWorkService workService;
}